home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / mxlibs / sblib / ex2.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1994-07-12  |  3.1 KB  |  138 lines

  1. /*Example 2.
  2.   Jouer un fichier raw.
  3.   Play from a raw file.
  4.  
  5. */
  6.  
  7. /* Include pour C++ */
  8. #include <sys\stat.h>
  9. #include <fcntl.h>
  10. #include <io.h>
  11. #include <stdlib.h>
  12. #include <dir.h>
  13. #include <stdio.h>
  14. #include <conio.h>
  15.  
  16. /* Include pour la librairie. */
  17. /* Include for library. */
  18. #include "type.h"
  19. #include "sbdsp.h"
  20. #include "status.h"
  21.  
  22.  
  23. /*
  24.   Fonction KbHit. Verifie si une touche a ete pesee.
  25.   retourne 0 si une touche est pesee,
  26.   retourne 1 si aucune touche pesee.
  27.   --
  28.   KbHit Function. Check for a key press.
  29.   return 0 if a key pressed,
  30.   otherwise 1.
  31.  
  32. */
  33. int KbHit( void )
  34. {
  35.    int retour = 1;
  36.  
  37.    asm mov ah,1;
  38.    asm int 016h;
  39.    if( (_FLAGS & 64) == 64 )
  40.       retour = 0;
  41.  
  42.    return retour;
  43. }
  44.  
  45.  
  46. /*
  47.   Fonction PrintCardInfo. Affiche les informations contenues
  48.   dans la structure stc_CARD_INFO.
  49.   ---
  50.   PrintCardInfo functions. Display stc_CARD_INFO
  51.  
  52. */
  53. void PrintCardInfo( stc_CARD_INFO *card )
  54. {
  55.  
  56.    printf("   Card Info.");
  57.    printf("\n\r   ----------");
  58.  
  59.  
  60.    printf("\n\n\n\rCard Name:%s",card->cardName);
  61.    printf("\n\rI/O port:%x",card->ioPort);
  62.    printf("\n\rIRQ     :%u",card->irq);
  63.    printf("\n\r8 bits dma:%u",card->dmaChanel8);
  64.    if( card->dmaChanel16 != sta_NOT_DEFINED )
  65.       printf("\n\r16 bits dma:%u",card->dmaChanel16);
  66.    else
  67.       printf("\n\r16 bits dma:N/A");
  68.    printf("\n\rDSP version:%u.%u",card->dspMaj, card->dspMin);
  69.    printf("\n\rCurrent Sampling rate:%u",card->samplingRate);
  70.    printf("\n\rMinimum Sampling rate:%u",card->minSamplingRate);
  71.    printf("\n\rMaximum Sampling rate:%u",card->maxSamplingRate);
  72.    getch();
  73.  
  74.  
  75. }
  76.  
  77.  
  78. main()
  79. {
  80.    SB_DSP dsp;
  81.    int handle;
  82.    unsigned flagFin = 0;
  83.  
  84.  
  85.    clrscr();
  86.    /* Ouverture du fichier raw */
  87.       /* Raw file open */
  88.    handle = open("c:rawfil.dat",O_RDONLY | O_BINARY,S_IREAD);
  89.  
  90.    if( dsp.Set8BitsDma(1) == err_VALID_DMA )
  91.    {
  92.       if( dsp.SetIOPort(0x220) == err_VALID_PORT )
  93.       {
  94.      if( dsp.SetIrq(5) == err_VALID_IRQ )
  95.      {
  96.         if( dsp.InitCard() == err_INIT_DONE )
  97.         {
  98.            /* Le fichier sera jouer a 20000Hz.
  99.           -------------------------------- */
  100.  
  101.            /* Play back rate at  20000Hz.
  102.           --------------------------- */
  103.  
  104.            dsp.SetSamplingRate(20000);
  105.            if( dsp.SetOutputRawHandle(handle) == err_VALID_HANDLE )
  106.            {
  107.           /* Donne l'adresse du flag qui
  108.              nous indiquera la fin du playback.
  109.              ---------------------------------- */
  110.  
  111.           /* Set flag address.
  112.              ----------------- */
  113.           dsp.SetUserFlag(&flagFin);
  114.           PrintCardInfo(dsp.GetCardInfo());
  115.  
  116.           /* On fait jouer le fichier jusqu'a la fin
  117.              ou jusqu'a ca qu'une touche soit peser.
  118.              --------------------------------------- */
  119.           dsp.Start();
  120.           while( !KbHit() && (flagFin == 0) );
  121.           dsp.Stop();
  122.            }
  123.            else
  124.           printf("Handle de fichier invalide.");
  125.         }
  126.         else
  127.            printf("Pas de carte trouve.");
  128.      }
  129.      else
  130.         printf("Invalide IRQ pour cette carte");
  131.       }
  132.       else
  133.      printf("Invalide IO port pour cette carte");
  134.    }
  135.    else
  136.       printf("Canal DMA 8 bits invalide pour cette carte");
  137.    close(handle);
  138. }